package com.wanjia.bpsapi.controller;

import com.wanjia.bpsapi.annotation.LoginToken;
import com.wanjia.bpsapi.crontab.TimedTaskBase;
import com.wanjia.bpsapi.crontab.TimedTaskUser;
import com.wanjia.bpsapi.crontab.TimedTaskVege;
import com.wanjia.bpsapi.crontab.TimedTaskVegePrice;
import com.wanjia.bpsapi.pojo.dto.VegeName;
import com.wanjia.bpsapi.pojo.dto.WjSupplierName;
import com.wanjia.bpsapi.pojo.dto.WjUserName;
import com.wanjia.bpsapi.pojo.model.JsonResult;
import com.wanjia.bpsapi.service.IVegetableService;
import com.wanjia.bpsapi.service.IWjStoreProductService;
import com.wanjia.bpsapi.service.IWjSupplierService;
import com.wanjia.bpsapi.service.IWjUserService;
import com.wanjia.bpsapi.util.JsonResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//其他第三方接口
@RestController("/other")
@Tag(name = "其他第三方接口")
public class OtherController extends BaseController {

    @Autowired
    IWjUserService iWjUserService;

    @Autowired
    IWjStoreProductService iWjStoreProductService;

    @Setter(onMethod_ = @Autowired)
    private IVegetableService vegetableService;

    @Autowired
    IWjSupplierService wjSupplierService;

    @Autowired
    TimedTaskBase timedTaskBase;

    @Autowired
    TimedTaskUser timedTaskUser;

    @Autowired
    TimedTaskVege timedTaskVege;

    @Autowired
    TimedTaskVegePrice timedTaskVegePrice;


    @GetMapping("/users")
    @Operation(summary = "获取客户列表接口")
    @Parameter(in = ParameterIn.HEADER, name = "token")
    @LoginToken
    public JsonResult<List<WjUserName>> getUsernames() {
        return JsonResultUtil.success(iWjUserService.getUsernames());
    }


    @GetMapping("/vege")
    @Operation(summary = "获取成本换算页面的菜品名称")
    @Parameter(in = ParameterIn.HEADER, name = "token")
    @LoginToken
    public JsonResult<List<VegeName>> getVegeNames() {
        return JsonResultUtil.success(vegetableService.getVegeNames());
    }

    @GetMapping("/base")
    @Operation(summary = "获取基地列表")
    @Parameter(in = ParameterIn.HEADER, name = "token")
    @LoginToken
    public JsonResult<List<WjSupplierName>> getBaseNames(){
        return new JsonResult<>(OK,wjSupplierService.getBaseNames());
    }

    @GetMapping("/flush")
    @Operation(summary = "获取基地列表")
    @Parameter(in = ParameterIn.HEADER, name = "token")
    @LoginToken
    public JsonResult flush(){
        timedTaskBase.run();
        timedTaskUser.run();
        timedTaskVege.run();
        timedTaskVegePrice.run();
        return new JsonResult<>(OK);
    }
}
